package com.yjy.aspect;

import lombok.AllArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@AllArgsConstructor
public class WebConfig implements WebMvcConfigurer {
    private final LoggingInterceptor loggingInterceptor;

    /**
     * 添加拦截器，默认执行顺序为添加顺序
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        /*
         * 添加拦截器
         * 通过addPathPatterns配置拦截器的拦截路径，可以多次调用该方法
         * 通过excludePathPatterns配置拦截器的不拦截路径，可以多次调用该方法
         */
        registry.addInterceptor(loggingInterceptor).addPathPatterns("/**");
    }
}